﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yu.Cms.Common;
using Yu.Cms.Web.Master;

namespace Yu.Cms.Web.UserCtrl.Default
{
    public partial class ContentC : BaseCtrl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int PostID = YuRequest.GetQueryInt("PostID", 0);
                this.OnStart(PostID);
            }
        }

        protected void OnStart(int PostID)
        {
            this.ShowInfo(PostID);
            this.ShowNavi(PostID);
            
        }


        /// <summary>
        /// 增加访问次数
        /// </summary>
        /// <param name="PostID"></param>
        protected void ShowInfo(int PostID)
        {
            bllContent.UpdateViewCount(PostID);
        }

        protected void ShowNavi(int PostID)
        {
            int BigTypeID, SmallTypeID;
            string BigTypeName, SmallTypeName;
            string ArticleTitle;

            Yu.Cms.Model.Content mContent = bllContent.GetModel(PostID);
            BigTypeID = mContent.BigTypeID;
            SmallTypeID = mContent.SmallTypeID;

            Yu.Cms.Model.BigType mBigType = bllBigType.GetModel(BigTypeID);
            BigTypeName = mBigType.BigTypeName;

            Yu.Cms.Model.SmallType mSmallType = bllSmallType.GetModel(SmallTypeID);
            SmallTypeName = mSmallType.SmallTypeName;

            hlNavb.NavigateUrl = "/Category.aspx?BigID=" + BigTypeID;
            hlNavb.Text = BigTypeName;
            hlNavb.ToolTip = "查看 " + BigTypeName + " 的全部文章";

            hlNavc.NavigateUrl = "/Category.aspx?SmlID=" + SmallTypeID;
            hlNavc.Text = SmallTypeName;
            hlNavc.ToolTip = "查看 " + SmallTypeName + " 的全部文章";

            ArticleTitle = lblTitle.Text = lblNav.Text = mContent.Title;

            lblPubDate.Text = GetYDateAndTime(mContent.PubTime);
            lblViewCount.Text = mContent.ViewCount.ToString();
            lblContent.Text = mContent.aContent;
            lblComment.Text = mContent.CommentCount.ToString();
           
            //文章标题
            (base.Page.Master.FindControl("lblTitle") as Literal).Text = ArticleTitle;
            this.ShowPrevNext(PostID, BigTypeID);
        }


        /// <summary>
        /// 绑定上一篇，下一篇
        /// </summary>
        /// <param name="PostID"></param>
        /// <param name="BigTypeID"></param>
        protected void ShowPrevNext(int PostID, int BigTypeID)
        {
            Yu.Cms.Model.Content mContent = bllContent.GetPrevNextModel(PostID,BigTypeID, Yu.Enum.Sort.up);
            hlPrev.NavigateUrl = "/Article.aspx?PostID=" + mContent.PostID;
            hlPrev.Text = mContent.Title;

            mContent = bllContent.GetPrevNextModel(PostID,BigTypeID, Yu.Enum.Sort.down);
            hlNext.NavigateUrl = "/Article.aspx?PostID=" + mContent.PostID;
            hlNext.Text = mContent.Title;
        }
        
    }
}